package com.ssy.lingxi.member.merchant.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.ssy.lingxi.member.merchant.handler.converter.JpaJsonToMapConverter;
import com.ssy.lingxi.member.merchant.handler.converter.JpaJsonToMemberDetailLabelConverter;
import com.ssy.lingxi.member.merchant.model.bo.MemberDetailLabelBO;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 会员入库资料
 * @author 万宁
 * @version 2.0.0
 * @date 2021-05-20
 */
@Entity
@Table(schema = "public", name = "ms_mc_member_deposit_detail", indexes = {@Index(name="ms_mc_member_deposit_detail_create_time_idx", columnList = "createTime"), @Index(name="ms_mc_member_deposit_detail_relation_id_idx", columnList = "relation_id"), @Index(name="ms_mc_member_deposit_detail_member_config_id_idx", columnList = "member_config_id"), @Index(name="ms_mc_member_deposit_detail_version_idx", columnList = "version")})
public class MemberDepositoryDetailDO implements Serializable {
    private static final long serialVersionUID = -1681813577817533947L;

    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="member_deposit_detail_seq")
    @SequenceGenerator(sequenceName="ms_mc_member_deposit_detail_seq", name="member_deposit_detail_seq",allocationSize = 1)
    private Long id;

    /**
     * 入库时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime createTime;

    /**
     * 多对一双向关联会员关系
     */
    @JsonBackReference
    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "relation_id")
    private MemberRelationDO relation;

    /**
     * 多对一单向关联注册资料配置
     */
    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "member_config_id", referencedColumnName = "id")
    private MemberConfigDO memberConfig;

    /**
     * 会员入库资料版本，定义在MemberDetailVersionEnum中，0-正在使用的版本，1-新增的待审核通过的版本
     */
    @Column
    private Integer version;

    /**
     * 分组名称
     */
    @Column(columnDefinition = "varchar(30)")
    private String groupName;

    /**
     * 字段名称
     */
    @Column(columnDefinition = "varchar(26)")
    private String fieldName;

    /**
     * 本地名称（中文名称）
     */
    @Column(columnDefinition = "varchar(30)")
    private String fieldLocalName;

    /**
     * 字段类型
     */
    @Column(columnDefinition = "varchar(20)")
    private String fieldType;

    /**
     * 字段类型附加属性
     */
    @Convert(converter = JpaJsonToMapConverter.class)
    @Column(columnDefinition = "jsonb")
    private Map<String, Object> attr;

    /**
     * 标签枚举，定义在MemberConfigTagEnum中，如不是标签字段为0
     */
    @Column
    private Integer tagEnum;

    /**
     * 是否启用
     */
    @Column
    private Integer status;

    /**
     * 变更是否需要重新审核
     */
    @Column
    private Integer validate;

    /**
     * 注册资料信息
     */
    @Column(columnDefinition = "varchar(500)")
    private String detail;

    /**
     * 省编码
     */
    @Column(columnDefinition = "varchar(10)")
    private String provinceCode;

    /**
     * 省名称
     */
    @Column(columnDefinition = "varchar(30)")
    private String provinceName;

    /**
     * 市编码
     */
    @Column(columnDefinition = "varchar(10)")
    private String cityCode;

    /**
     * 市名称
     */
    @Column(columnDefinition = "varchar(30)")
    private String cityName;

    /**
     * 区编码
     */
    @Column(columnDefinition = "varchar(10)")
    private String districtCode;

    /**
     * 区名称
     */
    @Column(columnDefinition = "varchar(30)")
    private String districtName;

    /**
     * 标签列表
     */
    @Convert(converter = JpaJsonToMemberDetailLabelConverter.class)
    @Column(columnDefinition = "jsonb")
    private List<MemberDetailLabelBO> labels;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public MemberRelationDO getRelation() {
        return relation;
    }

    public void setRelation(MemberRelationDO relation) {
        this.relation = relation;
    }

    public MemberConfigDO getMemberConfig() {
        return memberConfig;
    }

    public void setMemberConfig(MemberConfigDO memberConfig) {
        this.memberConfig = memberConfig;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getFieldLocalName() {
        return fieldLocalName;
    }

    public void setFieldLocalName(String fieldLocalName) {
        this.fieldLocalName = fieldLocalName;
    }

    public String getFieldType() {
        return fieldType;
    }

    public void setFieldType(String fieldType) {
        this.fieldType = fieldType;
    }

    public Map<String, Object> getAttr() {
        return attr;
    }

    public void setAttr(Map<String, Object> attr) {
        this.attr = attr;
    }

    public Integer getTagEnum() {
        return tagEnum;
    }

    public void setTagEnum(Integer tagEnum) {
        this.tagEnum = tagEnum;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getValidate() {
        return validate;
    }

    public void setValidate(Integer validate) {
        this.validate = validate;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public String getProvinceCode() {
        return provinceCode;
    }

    public void setProvinceCode(String provinceCode) {
        this.provinceCode = provinceCode;
    }

    public String getProvinceName() {
        return provinceName;
    }

    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }

    public String getCityCode() {
        return cityCode;
    }

    public void setCityCode(String cityCode) {
        this.cityCode = cityCode;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public String getDistrictCode() {
        return districtCode;
    }

    public void setDistrictCode(String districtCode) {
        this.districtCode = districtCode;
    }

    public String getDistrictName() {
        return districtName;
    }

    public void setDistrictName(String districtName) {
        this.districtName = districtName;
    }

    public List<MemberDetailLabelBO> getLabels() {
        return labels;
    }

    public void setLabels(List<MemberDetailLabelBO> labels) {
        this.labels = labels;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MemberDepositoryDetailDO that = (MemberDepositoryDetailDO) o;
        return id.equals(that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
